<?php
/*
*All rights reserved: Json.
*Links:http://www.liyaoquan.cn.
*Links:http://imarkchina.cn.
*Links:http://www.imarkchina.cn.
*/

/**
 * 博客前台公共控制器，负责，业务流程判断
 */
Class PublicAction extends Action{

	/**
	 * 博客标题
	 * @return [type] [description]
	 */
	Public function header(){
		$M = M('Indexpublic')->indexTitle();
		$this->assign('title', $M['title']);
		$this->assign('key', $M['key']);
		$this->assign('des', $M['des']);
		$this->display();
	}

	/**
	 * 博客名称
	 * @return [type] [description]
	 */
	Public function sitename(){
		$M = M('Public')->blogConfig();
		Ec($M['site_name']);
	}

	/**
	 * 博客第二个名称
	 * @return [type] [description]
	 */
	Public function sitenametwo(){
		$M = M('Public')->blogConfig();
		Ec($M['nametwo']);
	}

	/**
	 * 取昵称
	 * @return [type] [description]
	 */
	Public function nick(){
		$M = M('Public')->blogConfig();
		Ec($M['user_nick']);
	}

	/**
	 * AJax取点击数
	 * @return [type] [description]
	 */
	Public function hit(){
		$id = G('get.hid');
		$hits = loadfile(C('hits'));
		if (empty($hits[$id])) {
			Ec('100');
		} else {
			Ec($hits[$id]);
		}
	}

	/**
	 * Ajax取评论数
	 * @return [type] [description]
	 */
	Public function getpid(){
		$id = G('get.getpid');
		$pinglun = loadfile(C('pinglun.id').$id.'.php');
		if (empty($pinglun)) {
			Ec('0');
		} else {
			Ec(count($pinglun));
		}
	}

	/**
	 * 博客导航
	 * @return [type] [description]
	 */
	Public function top(){
		$M = M('Indexpublic')->indexTop();
		$this->assign('check', $M['check']);
		if ($M['check']) {
			$this->assign('lastarr', $M['lastarr']);
		}
		$this->assign('listarr', $M['listarr']);
		$this->display();
	}

	/**
	 * 边栏Ajax取评论
	 * @return [type] [description]
	 */
	Public function rightp(){
		$M = M('Indexpublic')->RightPingLun();
		$check = false;
		if (!$M) {
			$check = true;
		}
		$this->assign('check', $check);
		$this->assign('pinglun', $M);
		$this->display();
	}

	/**
	 * 博客边栏
	 * @return [type] [description]
	 */
	Public function right(){
		$M = M('Indexpublic')->indexRight();
		$this->assign('page', $M['page']);
		$this->assign('hot', $M['hot']);
		$this->assign('date', $M['date']);
		$this->assign('links', $M['links']);
		$this->assign('check', $M['check']);
		$this->display();
	}

	/**
	 * 博客底部
	 * @return [type] [description]
	 */
	Public function footer(){
		$M = M('Index')->indexfooter();
		$this->assign('title', $M['title']);
		$this->assign('time', $M['time']);
		$this->assign('copy', $M['copy']);
		$this->display();
	}

	/**
	 * 博客Rss
	 * @return [type] [description]
	 */
	Public function rss(){
		$M = M('Index')->indexPost();
		$C = M('Public')->blogConfig();
		$Rss = new Rss($C['site_name'],'', $C['site_desc'],'');
		foreach($M as $v){
			if (!URLREWRITE) {
				$url = str_replace('&', '&amp;', U('show/index', array('id' => $v['id'])));
			} else {
				$url = U('show/index', array('id' => $v['id']));
			}
			$Rss->AddItem($v['title'], $url,$v['des'],$v['date']);
		}
		$Rss->Display();
	}
}